﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DX.Learning.SimpleUserControlInsertion.SchoolSystemDbDataSetTableAdapters;

namespace DX.Learning.SimpleUserControlInsertion
{
    /// <summary>
    /// 
    /// </summary>
    public class SchoolSystemModel : Model
    {
        /// <summary>
        /// Gets or sets the data set.
        /// </summary>
        public SchoolSystemDbDataSet              DataSet           { get; set; }

        /// <summary>
        /// Gets or sets the table adapters.
        /// </summary>
        public TableAdapterManager                TableAdapters     { get; set; }

        /// <summary>
        /// Gets or sets the binding sources.
        /// </summary>
        public IDictionary<string, BindingSource> BindingSources    { get; set; }

        private TeacherTableAdapter adapter;

        protected override void Initialize()
        {
            

            DataSet = new SchoolSystemDbDataSet();
            TableAdapters = new TableAdapterManager();

            adapter = new TeacherTableAdapter();
            TableAdapters.TeacherTableAdapter = adapter;

            string message = string.Format("TableAdapters.TeacherTableAdapter is null : {0}",
                                           TableAdapters.TeacherTableAdapter == null);

            Console.WriteLine(message);
            TableAdapters.TeacherTableAdapter.Fill(DataSet.Teacher);

            Console.WriteLine(DataSet.Teacher.DefaultView.Count.ToString());

        }

        public BindingSource CreateBindingSource()
        {
            BindingSource mySource = new BindingSource();
            ((System.ComponentModel.ISupportInitialize)mySource).BeginInit();
            ((System.ComponentModel.ISupportInitialize)mySource).EndInit();
            return mySource;
        }

    }
}
